Skip to content

Require worktree isolation for spawned agent teams#3

Merged
axeldelafosse merged 1 commit intomainfrom
feat/interactive-followup-and-worktree-improvements
Feb 22, 2026
Merged

Require worktree isolation for spawned agent teams#3
axeldelafosse merged 1 commit intomainfrom
feat/interactive-followup-and-worktree-improvements

Conversation

@axeldelafosse
Copy link
Copy Markdown
Owner

@axeldelafosse axeldelafosse commented Feb 22, 2026

Summary

Update agent-team prompts to explicitly require worktree isolation when teams are spawned, and keep the requirement shared across prompt builders.

Changes

  • Added a shared instruction constant for team-spawning prompts.
  • Updated work and review prompts to include the required phrase.
  • Added test coverage for the new instruction in tests/loop/prompts.test.ts.

Notes

  • Prompt behavior for proof/callback instructions remains unchanged.

@axeldelafosse axeldelafosse force-pushed the feat/interactive-followup-and-worktree-improvements branch from 5837493 to bdf65c1 Compare February 22, 2026 06:25
Repository owner deleted a comment from gemini-code-assist bot Feb 22, 2026
@axeldelafosse axeldelafosse merged commit ad0de48 into main Feb 22, 2026
2 checks passed
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces significant changes to the main.ts, pr.ts, prompts.ts, and worktree.ts files, primarily to enhance the agent loop's functionality by incorporating worktree isolation and interactive follow-up prompts. The changes in main.ts refactor the main loop into a runIterations function and introduce an interactive mode for follow-up tasks. pr.ts is updated to handle existing pull requests by prompting for follow-up commits instead of creating new PRs. prompts.ts now includes a constant for worktree isolation phrasing, ensuring consistency across prompts. Finally, worktree.ts is modified to detect existing worktrees and move PLAN.md into the worktree, improving the isolation and setup process. The tests have been updated to reflect these new behaviors, covering the interactive mode, follow-up commits, and worktree detection logic.

I am having trouble creating individual review comments. Click here to see my feedback.

src/loop/main.ts (1)

medium

The createInterface import is added but not used in the runIterations function. It's only used in the runLoop function. It would be better to move this import to where it's actually used to improve modularity and reduce unnecessary imports in runIterations.

src/loop/main.ts (70)

medium

The interactive variable checks for process.stdin.isTTY or process.env.TMUX. While process.stdin.isTTY correctly identifies an interactive terminal, relying on process.env.TMUX might not be universally reliable across all environments or tmux configurations. It might be more robust to check for a specific --interactive flag if interactive behavior is critical, or ensure that TMUX is a consistent indicator in your environment.

src/loop/pr.ts (4-17)

medium

The buildDraftPrPrompt function now takes hasExistingPr as a parameter to conditionally build different prompts. This logic could be slightly cleaner by extracting the two prompt arrays into named constants or separate helper functions, improving readability and maintainability, especially if the prompts become more complex.

const PR_EXISTS_PROMPT_PARTS = [
  "A PR already exists for this branch. Send a follow-up commit to it.",
  (task: string) => `Task context:\n${task.trim()}`,
  "Commit your follow-up changes, push them, and return the commit in your final response.",
];

const NEW_PR_PROMPT_PARTS = [
  "Create a draft GitHub pull request for the current branch.",
  (task: string) => `Task context:\n${task.trim()}`,
  "Use `gh pr create --draft` with a clear title and description.",
  "If a PR already exists for this branch, do not create another one.",
  "Return the PR URL in your final response.",
];

const buildDraftPrPrompt = (task: string, hasExistingPr: boolean): string =>
  hasExistingPr
    ? PR_EXISTS_PROMPT_PARTS.map(part => typeof part === 'function' ? part(task) : part).join("\n\n")
    : NEW_PR_PROMPT_PARTS.map(part => typeof part === 'function' ? part(task) : part).join("\n\n");

src/loop/worktree.ts (1)

medium

The rmSync import is added but it's only used within the moveFile function in defaultDeps. It might be cleaner to define moveFile directly within defaultDeps or ensure all file system operations are grouped logically.

src/loop/worktree.ts (109-111)

medium

The moveFile implementation uses cpSync followed by rmSync. While this works, it's not an atomic operation. If the process crashes between cpSync and rmSync, the file might be duplicated or in an inconsistent state. For critical file movements, consider using fs.renameSync which is atomic, or implement more robust error handling and cleanup.

  moveFile: (source: string, target: string) => {
    renameSync(source, target);
  },

src/loop/worktree.ts (201)

medium

The removal of the deps.pathExists(candidatePath) check here means that the tryCreateWorktree function will now attempt to create a worktree even if the path already exists. This might lead to isWorktreeConflict being triggered more often, which is handled, but it changes the initial check. Ensure this is the intended behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant